<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>bs_info数据维护</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
	
	function openBsInfoAddDialog(){
		 $("#dlg").dialog("open").dialog("setTitle","添加Bs_Info信息");
		 $("#flag").val(1);
		 $("#regionId").attr("readonly",false);
	}
	
	function openBsInfoModifyDialog(){
		 var selectedRows=$("#dg").datagrid("getSelections");
		 if(selectedRows.length!=1){
			 $.messager.alert("系统提示","请选择一条要编辑的数据！");
			 return;
		 }
		 var row=selectedRows[0];
		 $("#dlg").dialog("open").dialog("setTitle","编辑Bs_Info信息");
		 $("#fm").form("load",row);
		 $("#flag").val(2);
		 $("#regionId").attr("readonly",true);
	}
	
	function saveBsInfo(){
		$("#fm").form("submit",{
			url:"${pageContext.request.contextPath}/bs_info/save.do",
			onSubmit:function(){
				return $(this).form("validate");
			},
			success:function(result){
				var result=eval('('+result+')');
				if(result.success){
					$.messager.alert("系统提示","保存成功！");
					resetValue();
					$("#dlg").dialog("close");
					$("#dg").datagrid("reload");
				}else{
					$.messager.alert("系统提示","保存失败！");
					return;
				}
			}
		 });
	}
	
	function checkData(){
		var flag=$("#flag").val();
		if(flag==1){
			$.post("${pageContext.request.contextPath}/bs_info/existRegionId.do",{RegionId:$("#regionId").val()},function(result){
				if(result.exist){
					 $.messager.alert("系统提示","RegionId已存在，请更换下！");
					 $("#regionId").focus();
				}else{
					saveBsInfo();
				}
			},"json");
		}else{
			saveBsInfo();
		}
	}
	
	function resetValue(){
		 $("#regionId").val("");
		 $("#frontProcessorId").val("");
		 $("#routeName").val("");
		 $("#provider").val("");
		 $("#BSName").val("");
		 $("#kilometerIndicator").val("");
		 $("#latitude").val("");
		 $("#longitude").val("");
		 $("#CGI").val("");
		 $("#LAC").val("");
		 $("#CI").val("");
		 $("#RAC").val("");
		 $("#BSIC").val("");
		 $("#carrierFrequencyNumber").val("");
		 $("#BCCH").val("");
		 $("#TCH1").val("");
		 $("#TCH2").val("");
		 $("#TCH3").val("");
		 $("#ownershipBSC").val("");
		 $("#BSGroupRing").val("");
		 $("#trafficModle").val("");
		 $("#IPAddress").val("");
		 $("#fres").val("");
		 $("#Equipmentmanufacturer").val("");
		 $("#model").val("");
		 $("#Deliverytime").val("");
		 $("#Maintenancerecords").val("");
	}
	
	function closeBsInfoDialog(){
		 $("#dlg").dialog("close");
		 resetValue();
	}
	
	function deleteBsInfo(){
		 var selectedRows=$("#dg").datagrid("getSelections");
		 if(selectedRows.length==0){
			 $.messager.alert("系统提示","请选择要删除的数据！");
			 return;
		 }
		 var strIds=[];
		 for(var i=0;i<selectedRows.length;i++){
			 strIds.push(selectedRows[i].regionId);
		 }
		 var ids=strIds.join(",");
		 $.messager.confirm("系统提示","您确定要删除这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r){
			 
			console.log(r);
			if(r){
				$.post("${pageContext.request.contextPath}/bs_info/delete.do",{bsIds:ids},function(result){
					if(result.success){
						 $.messager.alert("系统提示","数据已成功删除！");
						 $("#dg").datagrid("reload");
					}else{
						$.messager.alert("系统提示","数据删除失败，请联系系统管理员！");
					}
				},"json");
			} 
		 });
	}
	
	function exportBsInfoInCurrentPage(){
		var rows = $("#dg").datagrid("getRows");
		 var strIds=[];
		 for(var i=0;i<rows.length;i++){
			 strIds.push(rows[i].regionId);
		 }
		 var ids=strIds.join(",");
		 window.open('${pageContext.request.contextPath}/bs_info/export.do?bsIds='+ids+'');
	}
	
	function exportBsInfoInAllPages(){
		 window.open('${pageContext.request.contextPath}/bs_info/export.do?bsIds='+null+'');
	}
	
	function openUploadFileDialog_add(){
		$("#uploadFlag").val(1);
		$("#dlg2").dialog('open').dialog('setTitle','批量导入(追加)');
	}
	
	function openUploadFileDialog_overwrite(){
		$("#uploadFlag").val(2);
		$("#dlg2").dialog('open').dialog('setTitle','批量导入(覆盖)');
	}
	
	function downloadTemplate(){
		window.open('template/balise_infoExportTemplate.xls');
	}
	
	function uploadFile(){
		$("#uploadForm").form("submit",{
			success:function(result){
				var result=eval('('+result+')');
//				if(result.errorMsg){
//					$.messager.alert("系统提示",result.errorMsg);
//				}else{
//					$.messager.alert("系统提示","上传成功");
//					$("#dlg2").dialog("close");
//					$("#dg").datagrid("reload");
//				}
				if(result.success){
					$.messager.alert("系统提示","上传成功");
					$("#dlg2").dialog("close");
					$("#dg").datagrid("reload");
				}else{
					$.messager.alert("系统提示","上传失败！可能表格数据格式不正确，或者RegionId已存在！");
				}
			}
		});
	}
</script>
</head>
<body style="margin: 1px">
<table id="dg" title="Bs_Info数据维护" class="easyui-datagrid"
   fitColumns="true" pagination="true" rownumbers="true"  pageSize="100" pageList="[100,200,300,400,500]"
   url="${pageContext.request.contextPath}/bs_info/list.do" fit="true" toolbar="#tb" singleSelect="true">
   <thead>
   	<tr>
   		<th field="cb" checkbox="true" align="center"></th>
   		<th field="regionId" width="40" align="center">RegionId</th>
   		<th field="frontProcessorId" width="60" align="center">前置机ID</th>
   		<th field="routeName" width="80" align="center">RouteName</th>
   		<th field="provider" width="50" align="center">Provider</th>
   		<th field="BSName" width="50" align="center">小区名称</th>
   		<th field="kilometerIndicator" width="50" align="center">公里标</th>
   		<th field="latitude" width="50" align="center">维度</th>
   		<th field="longitude" width="50" align="center">经度</th>
   		<th field="CGI" width="50" align="center">CGI</th>
   		<th field="LAC" width="50" align="center">LAC</th>
   		<th field="CI" width="50" align="center">CI</th>
   		<th field="RAC" width="50" align="center">RAC</th>
   		<th field="BSIC" width="50" align="center">BSIC</th>
   		<th field="carrierFrequencyNumber" width="50" align="center">载波频率</th>
   		<th field="BCCH" width="50" align="center">BCCH</th>
   		<th field="TCH1" width="50" align="center">TCH1</th>
   		<th field="TCH2" width="50" align="center">TCH2</th>
   		<th field="TCH3" width="50" align="center">TCH3</th>
   		<th field="ownershipBSC" width="50" align="center">OwnershipBSC</th>
   		<th field="BSGroupRing" width="50" align="center">BSGroupRing</th>
   		<th field="trafficModle" width="50" align="center">TrafficModle</th>
   		<th field="IPAddress" width="50" align="center">IP地址</th>
   		<th field="fres" width="50" align="center">Fres</th>
   		<th field="equipmentmanufacturer" width="50" align="center">设备厂家</th>
   		<th field="model" width="50" align="center">型号</th>
   		<th field="deliverytime" width="50" align="center">出厂时间</th>
   		<th field="maintenancerecords" width="50" align="center">维修记录</th>
   	</tr>
   	  
   </thead>
 </table>
 <div id="tb">
 	<div>
 	<c:if test="${currentMemberShip.group.name=='管理员' }">
 		<a href="javascript:openBsInfoAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
 		<a href="javascript:openBsInfoModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
 		<a href="javascript:deleteBsInfo()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
 	</c:if>
 		<a href="javascript:exportBsInfoInCurrentPage()" class="easyui-linkbutton" iconCls="icon-save" plain="true">导出当前页Bs_Info</a>
 		<a href="javascript:exportBsInfoInAllPages()" class="easyui-linkbutton" iconCls="icon-save" plain="true">导出所有页Bs_Info</a>
 	<c:if test="${currentMemberShip.group.name=='管理员' }">
 		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="openUploadFileDialog_add()">导入数据(追加)</a>
 	    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="openUploadFileDialog_overwrite()">导入数据(覆盖)</a>
 	</c:if>
 	</div>
 </div>
 
 <div id="dlg" class="easyui-dialog" style="width:700px; height:500px; padding: 10px 20px" closed="true" buttons="#dlg-buttons">
   <form id="fm" method="post">
   	<table cellspacing="8px">
   		<tr>
   			<td>RegionId：</td>
   			<td><input type="text" id="regionId" name="regionId" class="easyui-validatebox" required="true"/></td>
   			<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
   			<td>前置机ID</td>
   			<td><input type="text" id="frontProcessorId" name="frontProcessorId" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
   			<td>RouteName：</td>
   			<td><input type="text" id="routeName" name="routeName" class="easyui-validatebox" required="true"/></td>
   			<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
   			<td>Provider：</td>
   			<td><input type="text" id="provider" name="provider" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
   			<td>小区名称：</td>
   			<td><input type="text" id="BSName" name="BSName" class="easyui-validatebox" required="true"/></td>
   			<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
   			<td>公里标：</td>
   			<td><input type="text" id="kilometerIndicator" name="kilometerIndicator" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
   			<td>维度：</td>
   			<td><input type="text" id="latitude" name="latitude" class="easyui-validatebox" required="true"/></td>
   			<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
   			<td>经度：</td>
   			<td><input type="text" id="longitude" name="longitude" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
   			<td>CGI：</td>
   			<td><input type="text" id="CGI" name="CGI" class="easyui-validatebox" required="true"/></td>
   			<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
   			<td>LAC：</td>
   			<td><input type="text" id="LAC" name="LAC" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
   			<td>CI：</td>
   			<td><input type="text" id="CI" name="CI" class="easyui-validatebox" required="true"/></td>
   			<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
   			<td>RAC：</td>
   			<td><input type="text" id="RAC" name="RAC" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
   			<td>BSIC：</td>
   			<td><input type="text" id="BSIC" name="BSIC" class="easyui-validatebox" required="true"/></td>
   			<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
   			<td>载波频率：</td>
   			<td><input type="text" id="carrierFrequencyNumber" name="carrierFrequencyNumber" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
   			<td>BCCH：</td>
   			<td><input type="text" id="BCCH" name="BCCH" class="easyui-validatebox" required="true"/></td>
   			<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
   			<td>TCH1：</td>
   			<td><input type="text" id="TCH1" name="TCH1" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
   			<td>TCH2：</td>
   			<td><input type="text" id="TCH2" name="TCH2" class="easyui-validatebox" required="true"/></td>
   			<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
   			<td>TCH3：</td>
   			<td><input type="text" id="TCH3" name="TCH3" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
   			<td>OwnershipBSC：</td>
   			<td><input type="text" id="ownershipBSC" name="ownershipBSC" class="easyui-validatebox" required="true"/></td>
   			<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
   			<td>BSGroupRing：</td>
   			<td><input type="text" id="BSGroupRing" name="BSGroupRing" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		
<!--    		<tr> -->
<!--    			<td>hdlc_id：</td> -->
<!--    			<td><input type="text" id="hdlc_id" name="hdlc_id" class="easyui-validatebox" required="true"/></td> -->
<!--    			<td>&nbsp;&nbsp;&nbsp;&nbsp;</td> -->
<!--    			<td>triggerTime：</td> -->
<!--    			<td><input type="text" id="triggerTime" name="triggerTime" class="easyui-validatebox" required="true"/></td> -->
<!--    		</tr> -->
   		<tr>
   			<td>TrafficModle：</td>
   			<td><input type="text" id="trafficModle" name="trafficModle" class="easyui-validatebox" required="true"/></td>
   			<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
   			<td>IP地址：</td>
   			<td><input type="text" id="IPAddress" name="IPAddress" class="easyui-validatebox" required="true"/>
   				<input type="hidden" id="flag" name="flag"/>
   			</td>
   		</tr>
   		<tr>
   			<td>Fres：</td>
   			<td><input type="text" id="fres" name="fres" class="easyui-validatebox" required="true"/></td>
   				<td>&nbsp;&nbsp;&nbsp;&nbsp;</td> 
   			<td>设备厂家：</td>
   			<td><input type="text" id="equipmentmanufacturer" name="equipmentmanufacturer" class="easyui-validatebox" required="true"/></td>
  
   		</tr>
   		<tr>
   			<td>型号：</td>
   			<td><input type="text" id="model" name="model" class="easyui-validatebox" required="true"/></td>
   				<td>&nbsp;&nbsp;&nbsp;&nbsp;</td> 
   			<td>出厂时间：</td>
   			<td><input type="text" id="deliverytime" name="deliverytime" class="easyui-datetimebox" required="true"/></td>
  
   		</tr>
   		<tr>
   			<td>维修记录：</td>
   			<td><input type="text" id="maintenancerecords" name="maintenancerecords" class="easyui-validatebox" required="true"/></td>
   			  
   		</tr>
   	</table>
   </form>
</div>
<!--  class="easyui-datetimebox"  -->
<div id="dlg-buttons">
	<a href="javascript:checkData()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
	<a href="javascript:closeBsInfoDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>

<div id="dlg2" class="easyui-dialog" style="width:400px;height:150px;padding:10px 20px" closed="true" buttons="#dlg-buttons2">
      <form id="uploadForm" action="${pageContext.request.contextPath}/bs_info/upload.do" method="post" enctype="multipart/form-data">
       	<table>
       		<tr>
       			<td>上传文件：</td>
       			<td><input type="file" name="userUploadFile">
       				<input type="hidden" id="uploadFlag" name="uploadFlag"/>
       			</td>
       		</tr>
       	</table>
       </form>
</div>
<div id="dlg-buttons2">
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="uploadFile()">上传</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg2').dialog('close')">关闭</a>
</div>

</body>
</html>